<template>
	<view class="content">
		<view class="top">
			<view class="back">
				<image src="../../static/login/back.png"></image>
			</view>
			<view class="center">Mike</view>
			<view class="right">
				<image src="../../static/login/more.png"></image>
			</view>
		</view>
		<scroll-view scroll-y="true">
			<view class="chatlist" v-for="(item,index) in chatInfo" :key='index'>
				<view class="date">{{item.date}}</view>
				<view class="talk" v-if="item.id!=1">
					<view class="talk-img">
						<image :src="item.img"></image>
					</view>
					<view class="jiantou"></view>
					<view class="talk-info" v-if="item.type=='text'">
						{{item.info}}
					</view>
					<view class="talk-info" v-else>
						<image class="img" :src="item.info" mode="widthFix" @tap="watchPic(item)"></image>
					</view>
				</view>
				<view class="me" v-else>
					<view class="talk-img">
						<image :src="item.img"></image>
					</view>
					<view class="jiantou"></view>
					<view class="talk-info" v-if="item.type=='text'">
						{{item.info}}
					</view>
					<view class="talk-info" v-else>
						<image class="img" :src="item.info" mode="widthFix" @tap="watchPic(item)"></image>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import data from '../../common/talkData.js'
	export default {
		data() {
			return {
				chatInfo: [],
				picList: []
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			getData() {
				var p = 0
				for (var i = 0; i < data.data().length; i++) {
					this.chatInfo.unshift(data.data()[i])
					if (data.data()[i].type == 'pic') {
						this.picList.unshift(data.data()[i].info)
					}
				}
			},
			watchPic(e) {
				var index = 0
				for (var i = 0; i < this.picList.length; i++) {
					if (this.picList[i] == e.info)
					index = i
				}//判断点击的图片位于图片数组的哪个位置
				uni.previewImage({
					current: index,
					urls: this.picList
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "../../common/top.scss";

	.content {
		height: 100%;
		background-color: rgb(244, 244, 244);
	}

	.top {
		background-color: rgb(244, 244, 244);

		.back {
			height: 88rpx;
			display: flex;
			align-items: center;

			image {
				margin-left: $uni-spacing-col-base;
				width: 28rpx;
				height: 48rpx;
			}
		}

		.center {
			position: absolute;
			margin-top: var(--status-bar-height);
			top: 16rpx;
			left: 50%;
			transform: translateX(-50%);
			text-align: center;
			height: 56rpx;
			line-height: 56rpx;
			font-size: 40rpx;
			font-weight: 600;
		}

		.right {
			height: 88rpx;
			display: flex;
			align-items: center;
			margin-right: 32rpx;

			image {
				width: 52rpx;
				height: 12rpx;
			}
		}
	}

	scroll-view {
		margin-top: 88rpx;
		width: 686rpx;
		padding: 28rpx 32rpx 0;
	}

	.chatlist {
		.date {
			font-size: 24rpx;
			color: rgba(39, 40, 50, 0.30);
			text-align: center;
			margin-bottom: 40rpx;
		}

		.talk,
		.me {
			position: relative;
			display: flex;
			margin-bottom: 40rpx;

			.talk-img {
				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 20rpx;
				}
			}

			.talk-info {
				display: flex;
				align-items: center;
				text-align: justify;
				max-width: 436rpx;
				border-radius: 20rpx;
				font-size: 32rpx;
				line-height: 40rpx;
				padding: 16rpx 22rpx;
			}

			.img {
				max-width: 400rpx;
				border-radius: 20rpx;
			}

			.jiantou {
				position: absolute;
				top: 24rpx;
				width: 0;
				height: 0;
				border: 16rpx solid;
			}
		}

		.talk {
			flex-direction: row;

			.talk-img {
				margin-right: 16rpx;
			}

			.talk-info {
				background-color: white;
			}

			.jiantou {
				left: 68rpx;
				border-color: transparent white transparent transparent;
			}
		}

		.me {
			flex-direction: row-reverse;

			.talk-img {
				margin-left: 16rpx;
			}

			.talk-info {
				background-color: $uni-color-primary;
			}

			.jiantou {
				right: 68rpx;
				border-color: transparent transparent transparent $uni-color-primary;
			}
		}
	}
</style>
